package com.java.servlets;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.java.dao.LibraryDao;
import com.java.dao.LibraryDaoI;
import com.java.domain.BookMasterAttributes;
import com.java.services.LibraryService;
import com.java.services.LibraryServiceI;




/**
 * Servlet implementation class for Servlet: LoginServlet mapping for this
 * servlet is /login
 */

public class BookMasterController extends javax.servlet.http.HttpServlet implements
		javax.servlet.Servlet {
	static final long serialVersionUID = 1L;

	/*
	 * (non-Java-doc)
	 * 
	 * @see javax.servlet.http.HttpServlet#HttpServlet()
	 */
	public BookMasterController() {
		super();
	}

	/*
	 * (non-Java-doc)
	 * 
	 * @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest request,
	 *      HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	/*
	 * (non-Java-doc)
	 * 
	 * @see javax.servlet.http.HttpServlet#doPost(HttpServletRequest request,
	 *      HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// Get Username and Password from Form
		System.out.println(" servlet testing ");

		String bookname = request.getParameter("bookName");
		String bookauthor = request.getParameter("bookAuthor");
		
		LibraryServiceI service = new LibraryService();  
		BookMasterAttributes bookMasterAttributes = service.setBookMasterData(bookname, bookauthor);
		System.out.println("In BookMasterController.doPost(), BookMasterAttributes:>>>>>>>> " + bookMasterAttributes);
		
		if (bookMasterAttributes != null ) {
			request.setAttribute("BookMasterAttributes", bookMasterAttributes);
			
			
			
			 RequestDispatcher view = getServletContext().getRequestDispatcher("/test.jsp");
			    view.forward(request, response);
	}       
			
 }	
	
}
		


